// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class COMMAND_EAC_U07 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("5 ECD",5)]
  	    [HL7Field(HL7Version.v25, 5, HL7Repeat.False, HL7Required.True,"ECD")]
	    public ECD ECD {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("6 TQ1",6)]
  	    [HL7Field(HL7Version.v25, 6, HL7Repeat.False, HL7Required.False,"TQ1")]
	    public TQ1 TQ1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("7 SPECIMEN_CONTAINER",7)]
  	    [HL7Field(HL7Version.v25, 7, HL7Repeat.False, HL7Required.False,"SPECIMEN_CONTAINER_EAC_U07")]
	    public SPECIMEN_CONTAINER_EAC_U07 SPECIMEN_CONTAINER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 CNS",11)]
  	    [HL7Field(HL7Version.v25, 11, HL7Repeat.False, HL7Required.False,"CNS")]
	    public CNS CNS {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ECD = PopSegmentParseAndCheckRequired<ECD>(availableData, options, "ECD");
			TQ1 = PopSegmentParseAndCheckRequired<TQ1>(availableData, options, "TQ1");
			SPECIMEN_CONTAINER = ProcessGroup<SPECIMEN_CONTAINER_EAC_U07>(availableData, options, "SPECIMEN_CONTAINER");
			CNS = PopSegmentParseAndCheckRequired<CNS>(availableData, options, "CNS");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isECD = availableData.StartsWith("ECD", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ECD", options.Version) || isECD) {
				return isECD;
			}
			bool isTQ1 = availableData.StartsWith("TQ1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("TQ1", options.Version) || isTQ1) {
				return isTQ1;
			}
			SPECIMEN_CONTAINER_EAC_U07 testSPECIMEN_CONTAINER_EAC_U07 = new SPECIMEN_CONTAINER_EAC_U07();
			bool grpCCSPECIMEN_CONTAINER_EAC_U07 = (testSPECIMEN_CONTAINER_EAC_U07.CanConsume(availableData, options));
			if (IsRequired("SPECIMEN_CONTAINER", options.Version) || grpCCSPECIMEN_CONTAINER_EAC_U07) {
				return grpCCSPECIMEN_CONTAINER_EAC_U07;
			}
			bool isCNS = availableData.StartsWith("CNS", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CNS", options.Version) || isCNS) {
				return isCNS;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "COMMAND";
			}
        }

        static COMMAND_EAC_U07() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(COMMAND_EAC_U07));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ECD != null) {
			string segmentValue = ECD.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (TQ1 != null) {
			string segmentValue = TQ1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (SPECIMEN_CONTAINER != null) {
			string segmentValue = SPECIMEN_CONTAINER.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (CNS != null) {
			string segmentValue = CNS.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

